function formatTime(value) {
  var theTime = parseInt(value); // 秒
  var theTime1 = 0; // 分
  var theTime2 = 0; // 小时
  if (theTime > 60) {
    theTime1 = parseInt(theTime / 60);
    theTime = parseInt(theTime % 60);
    if (theTime1 > 60) {
      theTime2 = parseInt(theTime1 / 60);
      theTime1 = parseInt(theTime1 % 60);
    }
  }
  var result = "" + parseInt(theTime) + "秒";
  if (theTime1 > 0) {
    result = "" + parseInt(theTime1) + "分" + result;
  }
  if (theTime2 > 0) {
    result = "" + parseInt(theTime2) + "小时" + result;
  }
  return result;
}

/**
 * 获取当前时间的方法
 * 
 */
let nowTime = function nowTime() {
  return new Promise((resolve, reject) => {
    var out = "";
    var now = new Date();
    console.log(now, Date.now())
    out += now.getFullYear();
    out += "年";
    out += (now.getMonth() + 1);
    out += "月";
    out += now.getDate();
    out += "日";
    out += now.getHours();
    out += "时";
    out += now.getMinutes();
    out += "分";
    resolve(out)
  })
}

//将时间戳转换成规定格式的时间的方法
let timeFormat = async function (time) {
  var date = new Date(time)
  let Y = date.getFullYear() + '年';
  let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '月';
  let D = date.getDate() + '日';
  let h = date.getHours() > 9 ? `${date.getHours()}时` : `0${date.getHours()}时`
  let m = date.getMinutes() > 9 ? `${date.getMinutes()}分` : `0${date.getMinutes()}分`
  return (Y + M + D + h + m);
}

module.exports = {
  formatTime,
  nowTime,
  timeFormat
}